package com.ys.http.network;


import android.util.Log;

import com.ys.http.entry.Resp;

import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;


public abstract class RespCallback<T> implements Observer<Resp<T>> {

    private int code;

    public RespCallback() {
    }

    public RespCallback(int code) {
        this.code = code;
    }

    @Override
    public void onSubscribe(@NonNull Disposable d) {

    }

    @Override
    public void onNext(@NonNull Resp<T> resp) {
        Log.e("RespCallback", "code-------->"+ resp.code);
        Log.e("RespCallback", "msg-------->"+ resp.msg);
        if (resp.code == code) {
            onSuccess(resp.data);
        } else {
            onError(new Throwable(resp.msg));
        }
    }

    public abstract void onSuccess(T t);

    @Override
    public void onComplete() {

    }

}
